package com.biz.primus.commodity.vo.evaluation;

import java.io.Serializable;
import java.util.List;

/**
 * @author yanweijin
 * @date 2016/12/22
 */
public class PageResult<E> implements Serializable {

	private int currentPage = 1;

	private int size = 10;

	private List<E> result;

	private int total;

	public PageResult(int currentPage, int size, long total, List<E> result) {
		if (result == null)
			throw new NullPointerException("分页结果不能为 null");
		this.currentPage = currentPage;
		this.size = size;
		this.result = result;
		this.total = (int) total;
		this.currentPage = Math.min(currentPage, this.getTotalPages());
	}

	// 用于 dubbo 序列化,平时不要使用
	public PageResult() {
	}

	public List<E> getResult() {
		return result;
	}

	public void setResult(List<E> result) {
		this.result = result;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = Math.min(currentPage, this.getTotalPages());
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
		this.currentPage = Math.min(this.currentPage, this.getTotalPages());
	}

	public int getTotalPages() {
		int totalPages = this.getTotal() / this.getSize() + (this.getTotal() % this.getSize() == 0 ? 0 : 1);
		return totalPages;
	}

}
